Repository navigation
fix(core): bypass gray-matter content cache when parsing frontmatter - #51245
Merged
Merged
Conversation
gray-matter populates its module-global content cache before parsing, so a failed YAML parse leaves a poisoned entry and every later parse of the same content returns it without throwing. In a long-lived serve process the first config load could sanitize an unquoted-colon frontmatter correctly, but every later instance init replayed the poisoned entry, never threw, and the skill was silently dropped by the empty-data check upstream. Passing an options object bypasses the cache read and write (gray-matter only caches when called with no options), making every parse deterministic and letting the sanitize fallback recover on each load. Regression test covers the repeat-parse recovery, the repeated throw for genuinely unparseable content, and plain content. Fixes anomalyco#51218
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
3 of 6 tasks
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #51218
Type of change
What does this PR do?
gray-matter writes to its module-global content cache before parsing (
matter.cache[file.content] = fileruns ahead ofparseMatter), so a failed YAML parse leaves a poisoned cache entry with no usable data. Every latermatter()call with the same content returns that entry without throwing — which is exactly whatConfigMarkdown.parsedoes: the first load in a server process could sanitize an unquoted-colon frontmatter correctly via the fallback, but every subsequent instance init replayed the poisoned entry, never threw, and the skill was silently dropped by the empty-data check upstream. Upstream report: jonschlinkert/gray-matter#166 (open since 2023).Passing an options object bypasses the cache read and write (gray-matter only caches when called with no options), so every parse is deterministic and the
sanitize()fallback recovers on each load. One-line change plus a regression test.How did you verify your code works?
packages/core/test/config/markdown.test.tswith 4 cases: sanitize fallback recovery, repeat-parse recovery after a failed parse, repeated throws for genuinely unparseable content, and plain no-frontmatter content. Red/green checked: the old uncached call fails 2 of the 4, the fix passes all 4.bun test test/config/markdown.test.ts test/config/skill.test.ts test/config/command.test.tsis 42 pass / 0 fail.bun typecheckclean.Screenshots / recordings
Not a UI change.
Checklist
Closes #51218